package chapter02;

import java.util.Scanner;

public class Training09 {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);

        System.out.print("请输入班级人数: ");
        int num = scanner.nextInt();
        double[] scores = new double[num];

        for (int i = 0; i < num; i++) {
            System.out.printf("请输入第%d个学生的成绩: ", i + 1);
            while (!scanner.hasNextDouble()) {
                System.out.println("输入错误，请输入一个双精度浮点数！");
                scanner.next(); // 清除错误输入
                System.out.printf("请输入第%d个学生的成绩: ", i + 1);
            }
            scores[i] = scanner.nextDouble();
        }

        double sum = 0;
        for (double score : scores) {
            sum += score;
        }
        double average = sum / num;
        System.out.printf("全班平均成绩为: %.2f\n", average);

        int high80 = 0, high70 = 0, high60 = 0, fail = 0;
        for (double score : scores) {
            if (score >= 80) high80++;
            else if (score > 70) high70++;
            else if (score > 60) high60++;
            else fail++;
        }

        System.out.println("成绩大于80分: " + high80);
        System.out.println("成绩大于70分: " + high70);
        System.out.println("成绩大于60分: " + high60);
        System.out.println("成绩不及格的人数: " + fail);

        scanner.close();
    }
    }



